package xworker.gluon.glisten.control;

import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
import javafx.scene.control.SelectionMode;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import xworker.javafx.beans.property.PropertyFactory;
import xworker.javafx.control.ControlActions;

public class ToggleButtonGroupActions {
    static{
        PropertyFactory.regist(ToggleButtonGroup.class, "selectionTypeProperty", o -> {
            ToggleButtonGroup obj = (ToggleButtonGroup) o;
            return obj.selectionTypeProperty();
        });
    }

    public static void init(ToggleButtonGroup node, Thing thing, ActionContext actionContext) {
        ControlActions.init(node, thing, actionContext);

        if (thing.valueExists("selectionType")) {
            node.setSelectionType(SelectionMode.valueOf(thing.getString("selectionType")));
        }
    }

    public static ToggleButtonGroup create(ActionContext actionContext) {
        Thing self = actionContext.getObject("self");
        ToggleButtonGroup node = new ToggleButtonGroup();
        init(node, self, actionContext);

        actionContext.peek().put("parent", node);
        for (Thing child : self.getChilds()) {
            child.doAction("create", actionContext);
        }

        actionContext.g().put(self.getMetadata().getName(), node);
        return node;
    }
}